program IniClr;

{$APPTYPE CONSOLE}

uses
  SysUtils, Classes;

var
  FileName: string;
  L, P: TStringList;
  I: Integer;
  S: string;

begin
  if (ParamCount > 0) then
  begin
    FileName :=ParamStr(1);
    if (FileExists(FileName)) then
    begin
      L := TStringList.Create;
      P := TStringList.Create;
      P.Delimiter := '=';
      try
        L.LoadFromFile(FileName);
        for I := L.Count - 1 downto 0 do
        begin
          S := Trim(L[I]);
          if (S = '') then
          begin
            L.Delete(I);
            Continue;
          end;
          if (Pos(P.Delimiter, S) > 0) then
          begin
            P.DelimitedText := S;
            S := Trim(P[1]);
            if (S = '') or (S = '0') then
            begin
              L.Delete(I);
              Continue;
            end;
          end;
          if (I > 0) and (Pos('[', S) > 0) then
          begin
            L.Insert(I, '');
            Continue;
          end;
        end;
        L.SaveToFile(FileName);
      finally
        P.Free;
        L.Free;
      end;
    end;
  end;
end.
